﻿using Mengsk.ProxyDelivery.Service;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace Mengsk.ProxyDelivery.App.UI.Accounting
{
    /// <summary>
    /// SellerRefundUserControl.xaml 的交互逻辑
    /// </summary>
    public partial class SellerRefundUserControl : UserControl, IPlugin
    {
        public SellerRefundUserControl()
        {
            InitializeComponent();
        }

        public string Title
        {
            get { return "退款管理"; }
        }

        public Control UIControl
        {
            get { return this; }
        }

        private void btnSearch_Click(object sender, RoutedEventArgs e)
        {
            this.pbBar.Parameters.Clear();
            int id = 0, sellerId = 0, orderChangeId = 0;
            long orderId = 0;
            int.TryParse(this.tbId.Text.Trim(), out id);
            int.TryParse(this.tbSellerId.Text.Trim(), out sellerId);
            int.TryParse(this.tbOrderChangeId.Text.Trim(), out orderChangeId);
            long.TryParse(this.tbOrderId.Text.Trim(), out orderId);

            this.pbBar.Parameters.Add("id", id);
            this.pbBar.Parameters.Add("sellerId", sellerId);
            this.pbBar.Parameters.Add("orderChangeId", orderChangeId);
            this.pbBar.Parameters.Add("orderId", orderId);
            this.pbBar.Parameters.Add("operator", this.tbOperator.Text.Trim());
            this.pbBar.Parameters.Add("startCreateTime", this.dpStart.SelectedDate == null ? DateTime.MinValue : this.dpStart.SelectedDate.Value.Date);
            this.pbBar.Parameters.Add("endCreateTime", this.dpEnd.SelectedDate == null ? DateTime.MinValue : this.dpEnd.SelectedDate.Value.Date.AddDays(1));
            this.pbBar.StartPage();
        }

        private void pbBar_PageChanging(object sender, PageBar.PageChangeEventArgs e)
        {
            var data = ServiceContainer.GetService<SystemRefundService>().GetByAll(e.GetParameter<int>("id"), e.GetParameter<int>("sellerId"), e.GetParameter<int>("orderChangeId"), e.GetParameter<long>("orderId"), e.GetParameter<string>("operator"), e.GetParameter<DateTime>("startCreateTime"), e.GetParameter<DateTime>("endCreateTime"), e.CurrentPage - 1, e.PageSize);
            this.dgvItems.ItemsSource = data.Datas;
            this.pbBar.Total = data.Total;
            this.pbBar.CurrentCount = data.Datas.Count;
        }
    }
}
